package kumiyunwii.kumi.config;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;

import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.util.Properties;

public class ElasticsearchConfig {
    private static TransportClient client;
    public TransportClient getElasticsearchClient() {
        try {
            Settings settings = Settings.builder()
                    .put("cluster.name", "docker-cluster")  //连接的集群名
                    .put("client.transport.ignore_cluster_name", true)  //如果集群名不对，也能连接
                    .build();

            //创建client
            client = new PreBuiltTransportClient(settings);
//                    .addTransportAddress(new TransportAddress(InetAddress.getByName("127.0.0.1"), 9300));  //主机和端口号
            return client;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
//注释